<!--

    Copyright © 2016-2025 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<mat-form-field [formGroup]="integrationTypeFormGroup" class="mat-block" appearance="outline">
  <mat-label translate>integration.type</mat-label>
  <input matInput type="text"
    #integrationTypeInput
    formControlName="type"
    (focusin)="onFocus()"
    (keyup.enter)="selectedType()"
    [required]="required"
    placeholder="{{ 'integration.select-integration-type' | translate }}"
    [matAutocomplete]="integrationTypesAutocomplete">
  @if (integrationTypeFormGroup.get('type').value && !disabled) {
    <button
      type="button"
      matSuffix mat-icon-button aria-label="Clear"
      (click)="clear()">
      <mat-icon class="material-icons">close</mat-icon>
    </button>
  }
  <mat-autocomplete class="tb-autocomplete tb-integration-type-autocomplete"
    [displayWith]="displayIntegrationTypeFn"
    #integrationTypesAutocomplete="matAutocomplete">
    <div class="flex flex-row flex-wrap">
      @for (integrationInfo of filteredIntegrationTypes | async; track integrationInfo) {
        <mat-option [value]="integrationInfo" class="max-w-50% flex-full xs:max-w-full">
          <div class="integration-type-button flex flex-row">
            <img class="icon" [src]="integrationInfo.icon" alt="icon">
            <div class="flex-1">
              <div class="name">{{ integrationInfo.name }}</div>
              <div class="description">{{ integrationInfo.description }}</div>
            </div>
          </div>
        </mat-option>
      }
    </div>
    @if (!(filteredIntegrationTypes | async)?.length) {
      <mat-option [value]="null" class="tb-not-found">
        <div class="tb-not-found-content" (click)="$event.stopPropagation()">
          {{ "integration.type-not-found" | translate }}
        </div>
      </mat-option>
    }
  </mat-autocomplete>
  <mat-icon matSuffix
            matTooltipClass="tb-error-tooltip"
            matTooltip="{{ 'integration.type-required' | translate }}"
            [class.!hidden]="!(integrationTypeFormGroup.get('type').hasError('required') && integrationTypeFormGroup.get('type').touched)"
            class="tb-error">
    warning
  </mat-icon>
</mat-form-field>
